<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cangjie CEF功能测试平台</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Arial', sans-serif;
        }
        
        body {
            overflow: hidden;
            background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
            height: 100vh;
            color: #fff;
            perspective: 1000px;
        }
        
        #canvas-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1;
        }
        
        .content {
            position: relative;
            z-index: 2;
            padding: 2rem;
            max-width: 1200px;
            margin: 0 auto;
            text-shadow: 0 0 10px rgba(0,0,0,0.7);
        }
        
        header {
            text-align: center;
            padding: 1rem 0 2rem;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            margin-bottom: 2rem;
        }
        
        h1 {
            font-size: 3.5rem;
            background: linear-gradient(to right, #ff7e5f, #feb47b);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            margin-bottom: 0.5rem;
            letter-spacing: 2px;
            animation: glow 2s infinite alternate;
        }
        
        .subtitle {
            font-size: 1.2rem;
            color: #a0a0ff;
            margin-bottom: 1rem;
        }
        
        .panels {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 2rem;
            margin-bottom: 2rem;
        }
        
        .panel {
            background: rgba(20, 20, 50, 0.6);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
            border: 1px solid rgba(255,255,255,0.1);
            transition: transform 0.3s, box-shadow 0.3s;
        }
        
        .panel:hover {
            transform: translateY(-5px) scale(1.02);
            box-shadow: 0 15px 35px rgba(0,0,0,0.4);
        }
        
        h2 {
            font-size: 1.8rem;
            margin-bottom: 1rem;
            color: #4fc3f7;
            display: flex;
            align-items: center;
        }
        
        h2 i {
            margin-right: 10px;
            font-size: 1.5rem;
        }
        
        .features {
            list-style: none;
        }
        
        .features li {
            padding: 0.8rem 0;
            border-bottom: 1px solid rgba(255,255,255,0.05);
            display: flex;
            align-items: center;
        }
        
        .features li:before {
            content: "✓";
            color: #64ffda;
            margin-right: 10px;
            font-weight: bold;
        }
        
        .controls {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            margin: 1rem 0;
        }
        
        button {
            flex: 1;
            min-width: 120px;
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 50px;
            background: linear-gradient(45deg, #2196F3, #21CBF3);
            color: white;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
        }
        
        button:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(33, 150, 243, 0.5);
        }
        
        button:active {
            transform: translateY(1px);
        }
        
        .btn-red {
            background: linear-gradient(45deg, #ff416c, #ff4b2b);
            box-shadow: 0 4px 15px rgba(255, 65, 108, 0.3);
        }
        
        .btn-green {
            background: linear-gradient(45deg, #00b09b, #96c93d);
            box-shadow: 0 4px 15px rgba(0, 176, 155, 0.3);
        }
        
        .btn-purple {
            background: linear-gradient(45deg, #654ea3, #da98b4);
            box-shadow: 0 4px 15px rgba(101, 78, 163, 0.3);
        }
        
        .performance {
            display: flex;
            justify-content: space-between;
            margin-top: 1rem;
            padding-top: 1rem;
            border-top: 1px solid rgba(255,255,255,0.1);
            font-size: 0.9rem;
            color: #aaa;
        }
        
        .footer {
            text-align: center;
            padding: 2rem 0;
            color: #7e8dff;
            font-size: 0.9rem;
        }
        
        .status {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #64ffda;
            margin-right: 8px;
            box-shadow: 0 0 10px #64ffda;
        }
        
        @keyframes glow {
            from { text-shadow: 0 0 5px #ff7e5f, 0 0 10px #ff7e5f; }
            to { text-shadow: 0 0 20px #ff7e5f, 0 0 30px #ff7e5f; }
        }
        
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        
        .floating {
            animation: float 4s ease-in-out infinite;
        }
    </style>
</head>
<body>
    <div id="canvas-container"></div>
    
    <div class="content">
        <header>
            <h1>Cangjie CEF功能测试平台</h1>
            <p class="subtitle">测试Cangjie CEF的渲染能力与性能</p>
        </header>
        
        <div class="panels">
            <div class="panel">
                <h2>3D渲染测试</h2>
                <p>使用Three.js创建的3D场景，测试WebGL渲染能力</p>
                <div class="controls">
                    <button id="addCube" class="btn-purple">添加立方体</button>
                    <button id="addSphere" class="btn-purple">添加球体</button>
                    <button id="clearScene" class="btn-red">清除场景</button>
                </div>
            </div>
            
            <div class="panel">
                <h2>粒子系统</h2>
                <p>测试复杂粒子系统的性能表现</p>
                <div class="controls">
                    <button id="startParticles" class="btn-green">启动粒子</button>
                    <button id="stopParticles" class="btn-red">停止粒子</button>
                </div>
                <div class="performance">
                    <span>粒子数量: <span id="particleCount">0</span></span>
                    <span>FPS: <span id="fpsCounter">0</span></span>
                </div>
            </div>
            
            <div class="panel">
                <h2>功能测试</h2>
                <ul class="features">
                    <li>WebGL 3D渲染支持</li>
                    <li>Canvas 2D绘图能力</li>
                    <li>CSS3动画与变换</li>
                    <li>JavaScript性能</li>
                    <li>复杂DOM操作</li>
                    <li>视频/音频播放</li>
                    <li>网络请求</li>
                    <li>本地存储</li>
                </ul>
            </div>
        </div>
        
        <div class="panel">
            <h2>系统状态</h2>
            <div class="performance">
                <span><span class="status"></span> WebGL状态: <span id="webglStatus">正在检测...</span></span>
                <span>渲染对象: <span id="renderObjects">0</span></span>
            </div>
        </div>
        
        <div class="footer">
            <p>CEF测试平台 | 当前时间: <span id="currentTime"></span> | 使用Three.js v128</p>
        </div>
    </div>

    <script>
        // 初始化Three.js场景
        let scene, camera, renderer;
        let cubes = [];
        let particles = [];
        let particleSystem = null;
        let particleGeometry, particleMaterial;
        let particleCount = 0;
        let isParticlesActive = false;
        
        // 性能监控
        let startTime = Date.now();
        let frameCount = 0;
        let fps = 0;
        
        function initThreeJS() {
            // 创建场景
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x0a0a2a);
            scene.fog = new THREE.Fog(0x0a0a2a, 10, 100);
            
            // 创建相机
            camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
            camera.position.z = 15;
            
            // 创建渲染器
            renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
            renderer.setSize(window.innerWidth, window.innerHeight);
            renderer.setPixelRatio(window.devicePixelRatio);
            document.getElementById('canvas-container').appendChild(renderer.domElement);
            
            // 添加灯光
            const ambientLight = new THREE.AmbientLight(0x404040);
            scene.add(ambientLight);
            
            const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
            directionalLight.position.set(1, 1, 1);
            scene.add(directionalLight);
            
            // 添加初始立方体
            addCube();
            
            // 创建粒子系统
            createParticleSystem();
            
            // 检测WebGL支持
            detectWebGL();
            
            // 启动动画循环
            animate();
            
            // 添加窗口大小调整监听
            window.addEventListener('resize', onWindowResize);
        }
        
        function addCube() {
            const geometry = new THREE.BoxGeometry(2, 2, 2);
            const material = new THREE.MeshPhongMaterial({ 
                color: Math.random() * 0xffffff,
                emissive: Math.random() * 0x222222,
                shininess: 80,
                wireframe: Math.random() > 0.7
            });
            
            const cube = new THREE.Mesh(geometry, material);
            
            // 随机位置
            cube.position.x = (Math.random() - 0.5) * 20;
            cube.position.y = (Math.random() - 0.5) * 10;
            cube.position.z = (Math.random() - 0.5) * 10;
            
            // 随机旋转速度
            cube.userData = {
                rotationSpeed: {
                    x: Math.random() * 0.02,
                    y: Math.random() * 0.02,
                    z: Math.random() * 0.02
                }
            };
            
            scene.add(cube);
            cubes.push(cube);
            updateRenderObjects();
        }
        
        function addSphere() {
            const geometry = new THREE.SphereGeometry(1.2, 32, 32);
            const material = new THREE.MeshPhongMaterial({ 
                color: Math.random() * 0xffffff,
                emissive: Math.random() * 0x222222,
                shininess: 100,
                wireframe: Math.random() > 0.7
            });
            
            const sphere = new THREE.Mesh(geometry, material);
            
            // 随机位置
            sphere.position.x = (Math.random() - 0.5) * 20;
            sphere.position.y = (Math.random() - 0.5) * 10;
            sphere.position.z = (Math.random() - 0.5) * 10;
            
            // 随机旋转速度
            sphere.userData = {
                rotationSpeed: {
                    x: Math.random() * 0.02,
                    y: Math.random() * 0.02,
                    z: Math.random() * 0.02
                }
            };
            
            scene.add(sphere);
            cubes.push(sphere);
            updateRenderObjects();
        }
        
        function clearScene() {
            cubes.forEach(cube => scene.remove(cube));
            cubes = [];
            updateRenderObjects();
        }
        
        function createParticleSystem() {
            particleGeometry = new THREE.BufferGeometry();
            const positions = new Float32Array(10000 * 3); // 10000个粒子
            
            for (let i = 0; i < 10000 * 3; i += 3) {
                positions[i] = (Math.random() - 0.5) * 100;
                positions[i + 1] = (Math.random() - 0.5) * 100;
                positions[i + 2] = (Math.random() - 0.5) * 100;
            }
            
            particleGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
            
            particleMaterial = new THREE.PointsMaterial({
                color: 0x4fc3f7,
                size: 0.1,
                transparent: true,
                opacity: 0.8,
                sizeAttenuation: true
            });
            
            particleSystem = new THREE.Points(particleGeometry, particleMaterial);
            particleSystem.visible = false;
            scene.add(particleSystem);
        }
        
        function toggleParticles(start) {
            if (particleSystem) {
                particleSystem.visible = start;
                isParticlesActive = start;
                particleCount = start ? 10000 : 0;
                document.getElementById('particleCount').textContent = particleCount;
            }
        }
        
        function animateParticles() {
            if (!isParticlesActive || !particleSystem) return;
            
            const positions = particleGeometry.attributes.position.array;
            
            for (let i = 0; i < positions.length; i += 3) {
                positions[i] += (Math.random() - 0.5) * 0.2;
                positions[i + 1] += (Math.random() - 0.5) * 0.2;
                positions[i + 2] += (Math.random() - 0.5) * 0.2;
            }
            
            particleGeometry.attributes.position.needsUpdate = true;
        }
        
        function animate() {
            requestAnimationFrame(animate);
            
            // 旋转立方体
            cubes.forEach(cube => {
                cube.rotation.x += cube.userData.rotationSpeed.x;
                cube.rotation.y += cube.userData.rotationSpeed.y;
                cube.rotation.z += cube.userData.rotationSpeed.z;
            });
            
            // 动画粒子
            animateParticles();
            
            // 旋转相机
            camera.position.x = Math.sin(Date.now() * 0.0005) * 10;
            camera.position.z = Math.cos(Date.now() * 0.0005) * 10;
            camera.lookAt(scene.position);
            
            renderer.render(scene, camera);
            
            // 更新FPS
            updateFPS();
        }
        
        function updateFPS() {
            frameCount++;
            const now = Date.now();
            const elapsed = now - startTime;
            
            if (elapsed >= 1000) {
                fps = Math.round((frameCount * 1000) / elapsed);
                document.getElementById('fpsCounter').textContent = fps;
                startTime = now;
                frameCount = 0;
            }
        }
        
        function updateRenderObjects() {
            document.getElementById('renderObjects').textContent = cubes.length;
        }
        
        function detectWebGL() {
            const statusElement = document.getElementById('webglStatus');
            try {
                if (renderer && renderer.capabilities) {
                    statusElement.textContent = "支持 (WebGL " + 
                        (renderer.capabilities.isWebGL2 ? "2.0" : "1.0") + ")";
                    statusElement.style.color = "#64ffda";
                } else {
                    throw new Error("WebGL not available");
                }
            } catch (e) {
                statusElement.textContent = "不支持";
                statusElement.style.color = "#ff416c";
            }
        }
        
        function onWindowResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        }
        
        // 更新当前时间
        function updateTime() {
            const now = new Date();
            document.getElementById('currentTime').textContent = 
                now.toLocaleTimeString();
        }
        
        // 初始化页面
        document.addEventListener('DOMContentLoaded', () => {
            initThreeJS();
            
            // 设置事件监听器
            document.getElementById('addCube').addEventListener('click', addCube);
            document.getElementById('addSphere').addEventListener('click', addSphere);
            document.getElementById('clearScene').addEventListener('click', clearScene);
            document.getElementById('startParticles').addEventListener('click', () => toggleParticles(true));
            document.getElementById('stopParticles').addEventListener('click', () => toggleParticles(false));
            
            // 初始时间更新
            updateTime();
            setInterval(updateTime, 1000);
            
            // 添加悬浮效果
            document.querySelectorAll('.panel, h1').forEach(el => {
                el.classList.add('floating');
            });
        });
    </script>
</body>
</html>